
"===================通用配置======================

"文件搜索路径
set path=.,/usr/include,,

" 控制
set nocompatible              "关闭vi兼容
filetype on                   "打开文件类型侦测
set fileencodings=utf-8,gbk,cp936,gb18030   "使用utf-8或gbk编码方式
syntax on                     "语法高亮
set backspace=2               "退格键正常模式
set whichwrap=<,>,[,]         "当光标到行首或行尾，允许左右方向键换行
set autoread                  "文件在vim外修改过，自动重载      
set nobackup                  "不使用备份
set confirm                   "在处理未保存或只读文件时，弹出确认消息   
set scrolloff=3               "光标移动到距离顶部或底部开始滚到距离
set history=1000              "历史记录数
set mouse=                    "关闭鼠标
set selection=inclusive       "选择包含最后一个字符
set selectmode=mouse,key      "启动选择模式的方式
set completeopt=longest,menu  "智能补全,弹出菜单，无歧义时才自动填充
set noswapfile                "关闭交换文件
set hidden                    "允许在有未保存的修改时切换缓冲区

"显示
set t_Co=256                  "可以使用的颜色数目
colorscheme default_color     "选择配色方案
set number                    "显示行号
set laststatus=2              "显示状态行
set ruler                     "显示标尺
set showcmd                   "显示输入的命令
set showmatch                 "高亮括号匹配
set matchtime=1               "匹配括号高亮的时间(十分之一秒)
set matchpairs={:},(:)	      "匹配括号"{}""()"	
set hlsearch                  "检索时高亮匹配项
set incsearch                 "边检索边显示匹配
set go-=T                     "去除gvim的toolbar
set guifont=Monospace\ 11     "gvim字体大小
set list                      "显示特殊字符
set listchars=tab:>-,trail:-  "TAB键和行尾多余空格   

"格式
"set expandtab                 "将tab转换为空格
set shiftwidth=4              "自动缩进的距离,也是平移字符的距离
set tabstop=4                 "tab键对应的空格数
set autoindent                "自动缩进
set smartindent               "智能缩进


"===================按键映射======================

"按键映射的起始字符
let mapleader = '\'             

"使用Ctrl-l 和 Ctrl+h 切换标签页
nnoremap <C-l> gt            
nnoremap <c-h> gT

"在行末加上分号
nnoremap <silent> <Leader>; :<Esc><End>a;<Esc><Down>
"增加printf调试
nnoremap <silent> <Leader>dp aprintf("\r\n %s:%d\r\n", __FUNCTION__, __LINE__);<Esc>
"替换
nnoremap <C-h> :%s/\<<C-R>=expand("<cword>")<CR>\>/<C-R>=expand("<cword>")<CR>/gc
"进入paster模式
nnoremap <silent> <Leader>mp :set paste<CR>
"退出paster模式
nnoremap <silent> <Leader>mnp :set nopaste<CR>
"删除行尾多余空格
nnoremap <silent> <Leader>rms :%s/\s\s*$//g<CR>
"替换行首空格为tab
nnoremap <silent> <Leader>tab :%s/^ \{4\}/\t/gc<CR>
"expandtab
nnoremap <silent> <Leader>ton :set noexpandtab<CR>
"noexpandtab
nnoremap <silent> <Leader>toff :set expandtab<CR>
"注释加空格
nnoremap <silent> <Leader>cl :%s/\/\*\([^ \*]\)/\/\* \1/gc<CR>
nnoremap <silent> <Leader>cr :%s/\([^ \*]\)\*\//\1 \*\//gc<CR>
"Esc
nnoremap <C-Backspace> <Esc>

"===================插件管理======================

" 将vundle加入到runtime path
call plug#begin('~/.vim/plugged')

" plugin on GitHub repo
Plug 'preservim/nerdtree'
Plug 'flazz/vim-colorschemes'
Plug 'vim-airline/vim-airline'
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' }
"Plug 'ycm-core/YouCompleteMe'
"Plug 'jeaye/color_coded'

"Plug 'inkarkat/vim-mark'
"Plug 'https://gitee.com/github-18274965/vim-mark'
"Plug 'inkarkat/vim-ingo-library'
"Plug 'https://gitee.com/github-18274965/vim-ingo-library'
"Plug 'ludovicchabant/vim-gutentags'
"Plug 'octol/vim-cpp-enhanced-highlight'
"Plug 'majutsushi/tagbar'
"Plug 'wincent/command-t'
"Plug 'prabirshrestha/vim-lsp'
"Plug 'mattn/vim-lsp-settings'

call plug#end()

filetype plugin indent on    "required

"===================插件配置======================

"-----NERDTree-----
let g:NERDTreeCaseSensitiveSort = 1
let g:NERDTreeWinSize = 25
let g:NERDTreeWinPos = "right"
nnoremap <silent> <Leader>tf :NERDTreeFind<CR> 
nnoremap <silent> <Leader>tt :NERDTreeToggle<CR> 

"-----tagBar--------
let g:tagbar_left = 1
let g:tagbar_autofocus = 1
let g:tagbar_sort = 0
nnoremap <silent> <Leader>dt :Tagbar<CR>

"------leaderf------
let g:Lf_ShowDevIcons=0
let g:Lf_UseVersionControlTool=0
let g:Lf_ShortcutF="<Leader>ff"
let g:Lf_ShortcutB="<Leader>fb"
let g:Lf_RootMarkers=['.project']
let g:Lf_PreviewCode=0
let g:Lf_PreviewInPopup=0
let g:Lf_GtagsSkipUnreadable=1
let g:Lf_GtagsSkipSymlink='a'
let g:Lf_GtagsStoreInRootMarker=1
let g:Lf_WildIgnore = {
        \ 'dir': ['.svn','.git','.hg'],
        \ 'file': ['*.[!ch]']
        \}
let g:Lf_RgConfig = [
    \ "-tc",
\ ]

nnoremap <Leader>fr :<C-U><C-R>=printf("Leaderf! gtags -r %s", expand("<cword>"))<CR><CR>
nnoremap <Leader>fd :<C-U><C-R>=printf("Leaderf! gtags -d %s", expand("<cword>"))<CR><CR>
nnoremap <Leader>fs :<C-U><C-R>=printf("Leaderf! gtags -s %s", expand("<cword>"))<CR><CR>
nnoremap <Leader>fg :<C-U><C-R>=printf("Leaderf! gtags -g %s", expand("<cword>"))<CR><CR>
nnoremap <Leader>fn :<C-U><C-R>=printf("Leaderf! gtags --next %s", "")<CR><CR>
nnoremap <Leader>fp :<C-U><C-R>=printf("Leaderf! gtags --previous %s", "")<CR><CR>
nnoremap <Leader>fo :<C-U><C-R>=printf("Leaderf! gtags --recall %s", "")<CR><CR>
nnoremap <Leader>fl :Leaderf! line --cword<CR>
nnoremap <Leader>fir :Leaderf! gtags -r  
nnoremap <Leader>fid :Leaderf! gtags -d  
nnoremap <Leader>fu :Leaderf! gtags --update<CR>
nnoremap <Leader>ft :Leaderf! bufTag --left --nowrap<CR>
nnoremap <Leader>fa :Leaderf gtags --all<CR>
nnoremap <Leader>gc :<C-U><C-R>=printf("Leaderf! rg --case-sensitive --auto-preview -e %s ", expand("<cword>"))<CR><CR> 
nnoremap <Leader>gs :Leaderf rg 
nnoremap <Leader>gi :LeaderfRgInteractive<CR>
nnoremap <Leader>go :Leaderf! rg --recall --auto-preview<CR>
nnoremap <Leader>gn :Leaderf! rg --next<CR>
nnoremap <Leader>gp :Leaderf! rg --previous<CR>

"-----YouCompleteMe-----
let g:ycm_complete_in_comments=1
let g:ycm_show_diagnostics_ui=0
let g:ycm_server_python_interpreter='/usr/bin/python3'
let g:ycm_confirm_extra_conf=0
let g:ycm_seed_identifiers_with_syntax=1 
let g:ycm_collect_identifiers_from_tags_files=0 
let g:ycm_use_clangd=1

nnoremap <silent><Leader>yr :YcmCompleter GoToReferences<CR>
nnoremap <silent><Leader>yd :YcmDiags<CR>
nnoremap <silent><Leader>ys :YcmRestartServer<CR>
nnoremap <silent><Leader>yi :YcmCompleter GoToInclude<CR>
nnoremap <silent><Leader>yg :YcmCompleter GoToDefinition<CR>
nmap <leader>yt <plug>(YCMHover)

" temporary
nnoremap <silent><Leader>r1 :%s/ESMC/VC12/gc<CR>
nnoremap <silent><Leader>r2 :%s/esmc/vc12/gc<CR>
nnoremap <silent><Leader>r3 :%s/Esmc/Vc12/gc<CR>
